home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / DEMON / RISCOS2 / TCP_131S.ARC / h / TIMER < prev    next >
Text File  |  1992-02-16  |  1KB  |  35 lines

  1. /* Software timers
  2.  * There is one of these structures for each simulated timer.
  3.  * Whenever the timer is running, it is on a doubly-linked list
  4.  * pointed to by "timers" so that the (hardware) timer interrupt
  5.  * can quickly run through the list and change counts and states.
  6.  * Stopping a timer or letting it expire causes it to be removed
  7.  * from the list; starting a timer puts it on the list.
  8.  */
  9. struct timer {
  10.         struct timer *next;     /* Doubly-linked-list pointers */
  11.         struct timer *prev;
  12.         int32 start;            /* Period of counter (load value) */
  13.         int32 count;            /* Ticks to go until expiration */
  14.         void (*func)();         /* Function to call at expiration */
  15.         char *arg;              /* Arg to pass function */
  16.         char state;             /* Timer state */
  17. #define TIMER_STOP      0
  18. #define TIMER_RUN       1
  19. #define TIMER_EXPIRE    2
  20. };
  21. #define NULLTIMER       (struct timer *)0
  22. #define MAX_TIME        (int32)4294967295ul       /* Max long integer */
  23.  
  24. #define MSPTICK         50  /* Milliseconds per tick for PC using clock() in pc.c */
  25.  
  26. /* Useful user macros that hide the timer structure internals */
  27. #define set_timer(t,x)  (((t)->start) = (x)/MSPTICK)
  28. #define dur_timer(t)    ((t)->start)
  29. #define read_timer(t)   ((t)->count)
  30. #define run_timer(t)    ((t)->state == TIMER_RUN)
  31.  
  32. void tick(void);
  33. void start_timer(struct timer *);
  34. void stop_timer(struct timer *);
  35.